#include "math_morph.h"
#include <stdlib.h>
#include <stdio.h>

//using namespace std;
class EE {
private:
	EEType type;
	pixel **Matrix;

public:
	EE(void);
	EE(EEType);
	~EE();

	void setType(void);
	void setType(EEType);
	EEType getType(void);

	void setMatrix(void);
	void setMatrix(EEType);
	pixel** getMatrix(void);

	void print();

};

EE::EE() {
	this->type = 0;
	this->Matrix = NULL;
}

EE::EE(EEType type) {
	this->type = type;
	setMatrix(type);
	this->Matrix = getMatrix();
}

EE::~EE() {
	delete Matrix;
	type = 0;
}

void EE::setType() {
	this->type = EE_TYPE_DEFAULT;
}

void EE::setType(EEType type) {
	this->type = type;
}

EEType EE::getType() {
	return this->type;
}

void EE::setMatrix() {
	setMatrix(EE_TYPE_DEFAULT);
}

void EE::setMatrix(EEType type) {
	int i, j;
	
	setType(type); 

	switch (type) {
	case EE_QUADRADO3X3:
		this->Matrix = (pixel **)malloc(3 * sizeof(pixel *));
		for (i = 0; i < 3; i++) {
			this->Matrix[i] = (pixel *)malloc(3 * sizeof(pixel));
		}
		for (i = 0; i < 3; i++) {
			for (j = 0; j < 3; j++) {
				this->Matrix[i][j] = 255;
			}
		}
		break;
	case EE_CRUZ3X3:
		this->Matrix = (pixel **)malloc(3 * sizeof(pixel *));
		for (i = 0; i < 3; i++) {
			this->Matrix[i] = (pixel *)malloc(3 * sizeof(pixel));
		}
		this->Matrix = (pixel **)malloc(3 * sizeof(pixel *));
		for (i = 0; i < 3; i++) {
			this->Matrix[i] = (pixel *)malloc(3 * sizeof(pixel));
		}
		for (i = 0; i < 3; i++) {
			for (j = 0; j < 3; j++) {
				if ((i == 1) || (j == 1)) {
					this->Matrix[i][j] = 255;
				} else {
					this->Matrix[i][j] = 0;
				}
			}
		}
		break;

	case EE_VERTICAL3X3:
		this->Matrix = (pixel **)malloc(3 * sizeof(pixel *));
		for (i = 0; i < 3; i++) {
			this->Matrix[i] = (pixel *)malloc(3 * sizeof(pixel));
		}
		for (i = 0; i < 3; i++) {
			for (j = 0; j < 3; j++) {
				if (j == 1) {
					this->Matrix[i][j] = 255;
				} else {
					this->Matrix[i][j] = 0;
				}
			}
		}
		break;

	case EE_HORIZONTAL3X3:
		this->Matrix = (pixel **)malloc(3 * sizeof(pixel *));
		for (i = 0; i < 3; i++) {
			this->Matrix[i] = (pixel *)malloc(3 * sizeof(pixel));
		}
		for (i = 0; i < 3; i++) {
			for (j = 0; j < 3; j++) {
				if (i == 1) {
					this->Matrix[i][j] = 255;
				} else {
					this->Matrix[i][j] = 0;
				}
			}
		}
		break;

	case EE_DIAGONALPRI3X3:
		this->Matrix = (pixel **)malloc(3 * sizeof(pixel *));
		for (i = 0; i < 3; i++) {
			this->Matrix[i] = (pixel *)malloc(3 * sizeof(pixel));
		}
		for (i = 0; i < 3; i++) {
			for (j = 0; j < 3; j++) {
				if (i == j) {
					this->Matrix[i][j] = 255;
				} else {
					this->Matrix[i][j] = 0;
				}
			}
		}
		break;

	case EE_DIAGONALSEC3X3:
		this->Matrix = (pixel **)malloc(3 * sizeof(pixel *));
		for (i = 0; i < 3; i++) {
			this->Matrix[i] = (pixel *)malloc(3 * sizeof(pixel));
		}
		for (i = 0; i < 3; i++) {
			for (j = 0; j < 3; j++) {
				if (i + j == 2) {
					this->Matrix[i][j] = 255;
				} else {
					this->Matrix[i][j] = 0;
				}
			}
		}
		break;
	default:
		this->Matrix = (pixel **)malloc(3 * sizeof(pixel *));
		for (i = 0; i < 3; i++) {
			this->Matrix[i] = (pixel *)malloc(3 * sizeof(pixel));
		}
		for (i = 0; i < 3; i++) {
			for (j = 0; j < 3; j++) {
				this->Matrix[i][j] = 255;
			}
		}
		break;
	}
}

pixel** EE::getMatrix() {
	return this->Matrix;
}

void EE::print() {
	char i, j;

	pixel **EE1 = getMatrix();

	for (i = 0; i < 3; i++) {
		for (j = 0; j < 2; j++) {
			printf("%d\t", EE1[i][j]);
		}
		printf("%d\n", EE1[i][2]);
	}

}

/*int main(int argc, char **argv) {
	EE *ee = new EE((argc >= 2) ? atoi(argv[1]) : 2);
	ee->print();
}*/

